﻿using System;
using System.Collections.Specialized;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Syndication;
using System.ServiceModel.Web;
using NCMIS.ObjectModel.Rest;
using System.Net;

namespace NCMIS.ServiceModel.Ra
{
    /// <summary>
    /// Holds the common properties for all partial service classes.
    /// </summary>
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public partial class Service : IService
    {
        /// <summary>
        /// Base URI to this service.
        /// </summary>
        Uri _baseUri = new Uri(CmisRestAtom.ServiceBaseUri, "Service.svc/");

        public Service()
        {
            RequestParameter = new RequestParameter();
        }

        public Service(IRequestParameter requestParam)
        {
            RequestParameter = requestParam;
        }

        /// <summary>
        /// Gets the request parameters as a <see cref="System.Collections.Specialized.NameValueCollection"/> for the current incomming request.
        /// </summary>
        private static NameValueCollection RequestParams
        {
            get
            {
                return WebOperationContext.Current != null ? WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters : new NameValueCollection();
            }
        }

        /// <summary>
        /// Retreives the service document for all available repositories. This is the starting point for client communication
        /// with the service. Exposes CMIS methods getRepositories and getRepositoryInfo.
        /// </summary>
        /// <returns>AtomPub Service document.</returns>
        [WebGet(UriTemplate = "/servicedoc")]
        public AtomPub10ServiceDocumentFormatter GetServiceDocument()
        {
            return this.GetServiceDocument(null);
        }

        /// <summary>
        /// Access the request parameters
        /// </summary>
        public IRequestParameter RequestParameter { get; set; }
    }
}
